import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
export var EventBus = /*#__PURE__*/function () {
  function EventBus() {
    _classCallCheck(this, EventBus);

    this.events = {};
  }

  _createClass(EventBus, [{
    key: "on",
    value: function on(evt, handler) {
      if (!this.events[evt]) {
        this.events[evt] = [];
      }

      this.events[evt].push(handler);
    }
  }, {
    key: "off",
    value: function off(evt, handler) {
      if (this.events[evt]) {
        this.events[evt] = this.events[evt].filter(function (h) {
          return h !== handler;
        });
      }
    }
  }, {
    key: "emit",
    value: function emit(evt) {
      for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }

      if (this.events[evt]) {
        this.events[evt].forEach(function (handle) {
          return handle.apply(void 0, args);
        });
      }
    }
  }]);

  return EventBus;
}();
export var pageEvents = new EventBus();